using System;
using System.Collections.Generic;
using System.Text;
using InfraStructureLayer;
using System.Collections;
using EntityLayer;
using DataLayer;
using DataAccessLayer;

namespace BusinessLayer
{
    public class Crypto
    {
        public string EncryptURL(string toEncrypt)
        {
            if (CurrentContext.Querystrings.ContainsKey(toEncrypt))
            {
                return CurrentContext.Querystrings[toEncrypt];
            }
            else
            {
                Guid g = Guid.NewGuid();

                DbConnector insDbConnector = new DbConnector();
                entQuerystrings insEntQuerystrings = new entQuerystrings();
                insEntQuerystrings.Guid = g;
                insEntQuerystrings.Querystring = toEncrypt;
                datQuerystrings insDatQuerystrings = new datQuerystrings();
                insDatQuerystrings.InsertQuerystrings(insEntQuerystrings,insDbConnector);
                CurrentContext.Querystrings.Add(toEncrypt, g.ToString());
                return g.ToString();
            }
        }
        public string DecryptURL(string cipherString)
        {
            foreach (KeyValuePair<string,string> de in CurrentContext.Querystrings)
            {
                if (de.Value == cipherString)
                {
                    return de.Key.ToString();
                }
            }
            return "";
        }
    }
}
